package com.boo2.controller;

import com.boo2.entity.Address;
import com.boo2.entity.Result;
import com.boo2.entity.Student;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author wzm
 * @create 2024-02-27 11:16
 * project_name:JavaWeb2401
 * @Description
 */
@RestController
public class ResponseController01 {

    //1.响应字符串
    @RequestMapping("/hello001")
    public Result hello01(){
        return Result.ok("hello01");
    }




//2.响应实体对象
@RequestMapping("/getStu001")
public Result getStu(){
    Student student = new Student(1, "zs", 20, null);
    if(student != null) {
        return Result.ok(student);
    }else{
        return Result.noOk("不知名错误");
    }
}

//3.响应集合数据
    @RequestMapping("/getList001")
    public Result getList(){
    List<Student> list = new ArrayList<>();
    Address address = new Address();
    address.setId(877);
    address.setCity("昆明");

    list.add(new Student(1, "zs1", 20, address));
    list.add(new Student(2, "zs2", 20, address));
    list.add(new Student(3, "zs3", 20, address));
    if(list != null) {
        return Result.ok(list);
    }else{
        return Result.noOk("有问题");
    }

    }



    @RequestMapping("/add")
    public Result add(){
        return Result.ok();
    }


}